﻿#include "settingdialog.h"
#include "ui_settingdialog.h"

#include <QSettings>

SettingDialog::SettingDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingDialog)
{
    ui->setupUi(this);
    initParam();
    ui->autoStartDaemon->setChecked(autoStartDaemon);
    ui->openScreenshot->setChecked(openScreenshot);
}

SettingDialog::~SettingDialog()
{
    delete ui;
}

void SettingDialog::initParam()
{
    QSettings settings(QCoreApplication::applicationDirPath()+"/"+"config/service.ini",QSettings::IniFormat);
    settings.setIniCodec("UTF-8");
    autoStartDaemon = settings.value("workParam/autoStartDaemon",false).toBool();
    openScreenshot = settings.value("workParam/openScreenshot",false).toBool();
}

void SettingDialog::uninitParam()
{
    QSettings settings(QCoreApplication::applicationDirPath()+"/"+"config/service.ini",QSettings::IniFormat);
    settings.setIniCodec("UTF-8");

    autoStartDaemon = ui->autoStartDaemon->isChecked();
    settings.setValue("workParam/autoStartDaemon",autoStartDaemon);

    openScreenshot = ui->openScreenshot->isChecked();
    settings.setValue("workParam/openScreenshot",openScreenshot);
}

void SettingDialog::on_saveBtn_clicked()
{
    uninitParam();
    QDialog::accept();
}

void SettingDialog::on_cancelBtn_clicked()
{
    QDialog::reject();
}
